#!/bin/bash
#
#
#    Run WARP3D for Windows -- OpenMPonly + MKL direct/iterative sparse solver
#    =========================================================================
#
#    --->>>  This script requires CygWin (free) software to be
#    --->>>  installed. www.cygwin.com
#
#    usage: warp3d_windows (number-of-threads) ( < input ) ( > output )
#
#           ( ) -- optional
#
#
echo " "
if [ $# = "0" ]; then
   echo ">> Usage:"; echo " "
   echo " warp3d_script_windows (<parms>) ( < input ) ( > output )"; echo " "
   echo " <parms>: <no. of threads>  "
   echo "  ( )  implies optional"
   echo " "
   exit 1
fi
echo " "
echo ">> Running WARP3D on Windows ..."
echo "   OpenMP + threaded MKL direct/iterative sparse solver"
#
if [ -z "$WARP3D_HOME" ]; then
   printf "[ERROR]\n"
   printf "... An environment variable WARP3D_HOME is not set.\n"
   printf "Quitting...\n"
   exit 1
fi
#
#           set executable file name for OpenMP + MKL sparse solver
#           version of warp3d
#
warp3d_exe="$WARP3D_HOME/run_windows_64/warp3d.exe"
#
#           set the number of threads for WARP3D execution and
#           for use by the MKL sparse solver. Here we just
#           assign the same number of threads for both.
#
#           default to 1 thread if user does nothing.
#
export OMP_NUM_THREADS=1
if [ $# = "1"  ]; then
    export OMP_NUM_THREADS=$1
fi
export MKL_NUM_THREADS=$OMP_NUM_THREADS
#
echo ">> Number of threads for parallel execution: " $OMP_NUM_THREADS
echo " "
#
#           make a core file in case WARP3D aborts. make it
#           unwritable so the core dump does not actually get
#           written.
#
touch core &> /dev/null
chmod ugo-rwx core
#
#           run WARP3D. The io-redirection files are automatically
#           passed thru the bash shell.
#
$warp3d_exe
#
/bin/rm -f core
exit
